layui.define(['layer'], function(exports){
    var layer = layui.layer;

    /**
     * 后台登录界面的提示
     */
    $('.ajax-login-form').on('submit', function() {
        var self = $(this);
        var email = self.find("#username");
        if(email.val() == ''){
            layer.tips('请填写用户名!', '#username', {
                tips: [1, '#c00']
            });
            return ;
        }

        var password = self.find("#password");
        if(password.val() == ''){
            layer.tips('请填写密码!', '#password', {
                tips: [1, '#c00']
            });
            return ;
        }

        var code = self.find("#verify");
        if(code.val() == ''){
            layer.tips('请填写验证码!', '#verify', {
                tips: [1, '#c00']
            });
            return ;
        }

        $.post(self.attr("action"), self.serialize(), success, "json");
        layer.closeAll();
        var loadIndex = layer.load(2,{shade: [0.1, '#676767']});
        function success(data){
            if(data.status){
                self.find(".btn-flat").text('登录中...');
                layer.close(loadIndex);
                layer.msg('登录中...',{shade: [0.3, '#676767']});
                setTimeout(function() {
                    window.location.href = data.url;
                }, 100);
            } else {
                layer.close(loadIndex);
                layer.msg(data.info,{area: '200px'})
                $("#CodeImg").click();//刷新验证码
            }
        }

        return false;
    });

    // 异步提交简单表单
    $('.ajaxForm').on('submit', function() {
        var self = $(this);
        $.post(self.attr("action"), self.serialize(), success, "json");
        layer.closeAll();
        var loadIndex = layer.load(2,{shade: [0.1, '#676767']});
        function success(data){
            if(data.status){
                layer.close(loadIndex);
                layer.msg(data.info,{shade: [0.3, '#676767']});
                setTimeout(function() {
                    window.location.href = data.url;
                }, 1000);
            } else {
                layer.close(loadIndex);
                layer.msg(data.info,{area: '200px'})
            }
        }

        return false;
    });



    exports('common', {});

});




